home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DMAKE38B.ARJ / MALLOPT.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  126 lines

  1. /*
  2.  * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  3.  * You may copy, distribute, and use this software as long as this
  4.  * copyright statement is not removed.
  5.  */
  6. #include <stdio.h>
  7. #include <fcntl.h>
  8. #include "malloc.h"
  9.  
  10. /*
  11.  * Function:    mallopt()
  12.  *
  13.  * Purpose:    to set options for the malloc debugging library
  14.  *
  15.  * Arguments:    none
  16.  *
  17.  * Returns:    nothing of any value
  18.  *
  19.  * Narrative:    
  20.  *
  21.  */
  22.  
  23. #ifndef lint
  24. static
  25. char rcs_hdr[] = "$Id: mallopt.c,v 1.1 1992/01/24 03:29:07 dvadura Exp $";
  26. #endif
  27.  
  28. int
  29. mallopt(cmd,value)
  30.     int              cmd;
  31.     union malloptarg      value;
  32. {
  33.     int              i;
  34.     extern int          malloc_checking;
  35.     extern char        * malloc_data_start;
  36.     extern int          malloc_errfd;
  37.     extern int          malloc_fatal_level;
  38.     void              malloc_init();
  39.     extern int          malloc_warn_level;
  40.     register char        * s;
  41.  
  42.     /*
  43.       * If not initialized...
  44.      */
  45.     if( malloc_data_start == (char *) 0)
  46.     {
  47.         malloc_init();
  48.     }
  49.  
  50.  
  51.     switch(cmd)
  52.     {
  53.         case MALLOC_WARN:
  54.             malloc_warn_level = value.i;
  55.             break;
  56.  
  57.         case MALLOC_FATAL:
  58.             malloc_fatal_level = value.i;
  59.             break;
  60.  
  61.         case MALLOC_CKCHAIN:
  62.             malloc_checking = value.i;
  63.             break;
  64.  
  65.         case MALLOC_ERRFILE:
  66.             
  67.             i = open(value.str,O_CREAT|O_APPEND|O_WRONLY,0666);
  68.             if( i == -1 )
  69.             {
  70.                 (void) write(2,
  71.                       "Unable to open malloc error file: ",
  72.                       (unsigned) 34);
  73.                 for(s=value.str; *s; s++)
  74.                 {
  75.                     /* do nothing */;
  76.                 }
  77.                 (void) write(2,value.str,
  78.                          (unsigned)(s-value.str));
  79.                 (void) write(2,"\n",(unsigned)1);
  80.             }
  81.             else
  82.             {
  83.                 if( malloc_errfd != 2 )
  84.                 {
  85.                     (void) close(malloc_errfd);
  86.                 }
  87.                 malloc_errfd = i;
  88.             }
  89.             
  90.             break;
  91.  
  92.         default:
  93.             return(1);
  94.     }
  95.  
  96.     return(0);
  97. }
  98.  
  99. /*
  100.  * $Log: mallopt.c,v $
  101.  * Revision 1.1  1992/01/24  03:29:07  dvadura
  102.  * dmake Version 3.8, Initial revision
  103.  *
  104.  * Revision 1.6  90/08/29  22:23:36  cpcahil
  105.  * fixed mallopt to use a union as an argument.
  106.  * 
  107.  * Revision 1.5  90/08/29  21:22:51  cpcahil
  108.  * miscellaneous lint fixes
  109.  * 
  110.  * Revision 1.4  90/05/11  00:13:10  cpcahil
  111.  * added copyright statment
  112.  * 
  113.  * Revision 1.3  90/02/25  11:03:26  cpcahil
  114.  * changed to return int so that it agrees with l libmalloc.a's mallopt()
  115.  * 
  116.  * Revision 1.2  90/02/25  11:01:21  cpcahil
  117.  * added support for malloc chain checking.
  118.  * 
  119.  * Revision 1.1  90/02/24  21:50:24  cpcahil
  120.  * Initial revision
  121.  * 
  122.  * Revision 1.1  90/02/24  17:10:53  cpcahil
  123.  * Initial revision
  124.  * 
  125.  */
  126.